<template>
  <div class="admin">
    <el-container style="height: 100%; border: 1px solid #eee">
      <el-header>
        <div style="color: white; font-size: 20px">宠物管理中心</div>
        <div style="display: flex">
          <div style="margin-right: 30px; color: #eee; font-size: 14px">
            当前时间：{{ nowTime }}
          </div>
          <el-dropdown>
            <span>{{ 1 }}</span>
            <i class="el-icon-setting" style="margin-left: 5px"></i>
            <el-dropdown-menu slot="dropdown">
              <el-dropdown-item @click.native="signOut">注销</el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>
        </div>
      </el-header>

      <el-container>
        <el-aside width="200px" style="background-color: rgb(238, 241, 246)">
          <el-menu :default-active="activeIndex" router>
            <el-submenu index="1">
              <template slot="title"
                ><i class="el-icon-coordinate"></i>系统管理</template
              >
              <el-menu-item-group>
                <el-menu-item index="/banner">轮播图</el-menu-item>
              </el-menu-item-group>
            </el-submenu>
          </el-menu>
        </el-aside>
        <el-main style="height: 90vh; overflow-y: scroll">
          <router-view></router-view>
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>

<script>
import { RouterView } from "vue-router";

export default {
  // eslint-disable-next-line vue/multi-word-component-names
  name: "admin",
  components: { RouterView },
  data() {
    return {
      nowTime: "",
      activeIndex: "/banner-manager",
    };
  },
  created() {
    this.nowTimes();
  },
  methods: {
    // 计算时间
    timeFormate(timeStamp) {
      let year = new Date(timeStamp).getFullYear();
      let month =
        new Date(timeStamp).getMonth() + 1 < 10
          ? "0" + (new Date(timeStamp).getMonth() + 1)
          : new Date(timeStamp).getMonth() + 1;
      let date =
        new Date(timeStamp).getDate() < 10
          ? "0" + new Date(timeStamp).getDate()
          : new Date(timeStamp).getDate();
      let hh =
        new Date(timeStamp).getHours() < 10
          ? "0" + new Date(timeStamp).getHours()
          : new Date(timeStamp).getHours();
      let mm =
        new Date(timeStamp).getMinutes() < 10
          ? "0" + new Date(timeStamp).getMinutes()
          : new Date(timeStamp).getMinutes();
      let ss =
        new Date(timeStamp).getSeconds() < 10
          ? "0" + new Date(timeStamp).getSeconds()
          : new Date(timeStamp).getSeconds();
      let week = new Date(timeStamp).getDay();
      let weeks = ["日", "一", "二", "三", "四", "五", "六"];
      let getWeek = "星期" + weeks[week];
      this.nowTime =
        year +
        "-" +
        month +
        "-" +
        date +
        " " +
        getWeek +
        " " +
        hh +
        ":" +
        mm +
        ":" +
        ss;
    },
    nowTimes() {
      this.timeFormate(new Date());
      setInterval(this.nowTimes, 1000);
      this.clear();
    },
    clear() {
      clearInterval(this.nowTimes);
      this.nowTimes = null;
    },
    // 退出
    signOut() {
      this.$cookies.remove("userMessage");
      this.$router.replace("/login");
    },
  },
};
</script>
<style lang="less" scoped>
.admin {
  width: 100%;
  height: 100vh;
  background-color: #f0f2f5;
  .el-header {
    background-color: #b3c0d1;
    color: #333;
    line-height: 60px;
    font-size: 16px;
    display: flex;
    justify-content: space-between;
  }

  .el-aside {
    color: #333;
  }
  .el-main {
    background-color: #f0f2f5;
  }
}
</style>
